package config

import (
	"github.com/spf13/viper"
)

type NacosConfig struct {
	IP          string  `mapstructure:"ip"`
	Port        uint64  `mapstructure:"port"`
	Namespace   string  `mapstructure:"namespace"`
	Group       string  `mapstructure:"group"`
	ServiceName string  `mapstructure:"service_name"`
	Weight      float64 `mapstructure:"weight"`
	GrpcPort    uint64  `mapstructure:"grpc_port"`
	TimeoutMs   uint64  `mapstructure:"timeout_ms"`
	LocalIp     string  `mapstructure:"local_ip"`
}

type ServerConfig struct {
	Port uint64 `mapstructure:"port"`
}

var NacosConf NacosConfig
var ServerConf ServerConfig

func LoadConfig() {
	viper.SetConfigFile("sf-backend-gateway/resource/gateway.yml")
	if err := viper.ReadInConfig(); err != nil {
		panic(err)
	}
	if err := viper.UnmarshalKey("nacos", &NacosConf); err != nil {
		panic(err)
	}
	if err := viper.UnmarshalKey("server", &ServerConf); err != nil {
		panic(err)
	}
}
